import { request } from '@/utils'
import type { Params } from '@/types'

import type { IDataEntity } from '@/types'
import { DataEntity } from '@/utils/entity'

interface IAccount extends IDataEntity {
  name: string
  username: string
}

export interface IUser extends IDataEntity {
  account: IAccount
  code: string
  name: string
}

export async function userSession(): Promise<IUser> {
  const resp = await request.post<IUser, {}>('/auth/user/session', {})
  return resp
}

// org test
export interface IDimOrg {
  id: string
  orgId: string
  orgName: string
  orgSort: number
  orgStatus: string
}
export async function queryOrg(params: Params = {}): Promise<IDimOrg[]> {
  const url = '/entityData/dimOrg/all'
  const disOrgList = await request.query<IDimOrg[]>(url, params)
  return disOrgList
}

// dict
class Dict extends DataEntity {
  name: string
  value: string
  sort: number
  constructor(props: Dict) {
    super(props)
    this.name = props.name
    this.value = props.value
    this.sort = props.sort
  }
}
export async function queryDict(params: Params = {}): Promise<Dict[]> {
  const url = '/system/dictionary/all'
  const dictList = await request.query<Dict[]>(url, params)
  return dictList.map((item) => new Dict(item))
}
